//
//  XSAddViewController.m
//  XSDataBaseDemo
//
//  Created by 大帅 on 2023/12/19.
//

#import "XSAddViewController.h"

@interface XSAddViewController ()
// 用户id
@property (nonatomic, assign) NSInteger userId;

@end

@implementation XSAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"增";
    self.view.backgroundColor = [UIColor.orangeColor colorWithAlphaComponent:1];
    self.userId = 100;
    
    UILabel *lab = [[UILabel alloc] init];
    lab.text = @"点击空白新增一条数据";
    [self.view addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.view);
    }];
    
}

// 点击增加空白增加一条数据
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    // 用户id自增
    NSArray *allArr = [[XSDataSaveManager sharedManager] lookDownloadAllData];
    if (allArr.count > 0) {
        XSTestModel *model = allArr.lastObject;
        self.userId = model.userId.integerValue + 1;
    } else {
        self.userId = 100;
    }
    XSTestModel *model = [[XSTestModel alloc] init];
    model.userId = [NSString stringWithFormat:@"%ld", self.userId];
    model.userName  = @"西北&锤王";
    model.userAge   = @"18";
    model.userPhone = @"18888888888";
    [[XSDataSaveManager sharedManager] addDownloadSingleData:model];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
